home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / pascal / tpfast30.zip / FASTSTR.ASM < prev    next >
Assembly Source File  |  1990-09-26  |  51KB  |  943 lines

  1. ;   _______________________________________________________________
  2. ;  |                                                               |
  3. ;  |            Copyright (C) 1989,1990  Steven Lutrov             |
  4. ;  |_______________________________________________________________|____
  5. ;  |                                                               |    |
  6. ;  |  Program Title : FastStr.Asm                                  |    | ___
  7. ;  |  Author        : Steven Lutrov                                |    |    |
  8. ;  |  Revision      : 2.01                                         |    |    |
  9. ;  |  Date          : 1990-03-16                                   |    |    |
  10. ;  |  Language      : Turbo Assembler                              |    |    |
  11. ;  |                                                               |    |    |
  12. ;  |  Description   : Assembly Functions For String Manipulation.  |    |    |
  13. ;  |                : Tested on Turbo Pascal 5.0 & 5.5             |    |    |
  14. ;  |                                                               |    |    |
  15. ;  |_______________________________________________________________|    |    |
  16. ;      |                                                                |    |
  17. ;      |________________________________________________________________|    |
  18. ;          |                                                                 |
  19. ;          |_________________________________________________________________|
  20. ;
  21.  
  22.  
  23. Code    Segment Word  Public
  24.  
  25. Assume  Cs:Code,Ds:Data
  26.  
  27. Public  Changechar,Compare,Stringend,Deletechar,Deleteleft,Deleteright
  28. Public  Leftend,Lowercase,Overwrite,Padcentre,Padends,Padleft,Padright
  29. Public  Replace,Rightend,Seekstring,Stringof,Uppercase,Wordcount
  30.  
  31.  
  32. ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  33. ;Procedure Changechar(Var Strx: Stype; Search,Replace: Char);
  34. ;
  35. ;
  36. Data    Segment
  37.         Extrn  Errreturn:Byte
  38. Data    Ends
  39. ;
  40. ;
  41. Changechar Proc Far
  42.                 Push Bp                         ;Save Bp
  43.                 Mov  Bp,Sp                      ;Set Up Stack Frame
  44.                 Mov  Errreturn,0                ;Assume Char Found
  45.                 Les  Di,Dword Ptr[Bp+10]        ;Es:Di Pts To Strx
  46.                 Sub  Dx,Dx                      ;Flags That A Char Found
  47.                 Mov  Al,[Bp+6]                  ;Get Replacement Char
  48.                 Mov  Ah,[Bp+8]                  ;Search Character
  49.                 Sub  Cx,Cx                      ;Clear Cx
  50.                 Mov  Cl,Es:[Di]                 ;Get String Length
  51.                 Jcxz Changechar3                ;Quit If Null String
  52. Changechar1:    Inc  Di                         ;Forward String Ptr
  53.                 Cmp  Es:[Di],Ah                 ;Search Char?
  54.                 Jne  Changechar2                ;Jump Ahead If Not
  55.                 Mov  Es:[Di],Al                 ;Else Change Char
  56.                 Inc  Dx                         ;Flag That A Char Found
  57. Changechar2:    Loop Changechar1                ;Go Do Next Char
  58.                 Or   Dx,Dx                      ;Test If Char Found
  59.                 Jnz  Changechar4                ;Jump Ahead If So
  60. Changechar3:    Inc  Errreturn                  ;Else 1 = Char Not Found
  61. Changechar4:    Pop  Bp                         ;Restore Bp And Quit
  62.                 Ret  8
  63. Changechar Endp
  64.  
  65.  
  66. ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  67. ;Function Compare(Strg1,Strg2: Stype): Boolean;
  68. ;
  69. ;
  70. Compare Proc Far
  71.                 Mov  Bx,Sp                      ;Bx Pts To Stack
  72.                 Push Ds                         ;Save Turbo'S Ds
  73.                 Les  Di,Ss:Dword Ptr[Bx+8]      ;Es:Di Pts To Strg1
  74.                 Lds  Si,Ss:Dword Ptr[Bx+4]      ;Ds:Si Pts To Strg2
  75.                 Sub  Cx,Cx                      ;Clear Cx
  76.                 Mov  Cl,[Si]                    ;Get Strg2 Length
  77.                 Cmp  Cl,Es:[Di]                 ;Equal To Strg1 Length?
  78.                 Jne  Compare6                   ;Quit If Not
  79.                 Jcxz Compare5                   ;Quit If Both Null
  80. Compare1:       Inc  Di                         ;Forward Strg1 Ptr
  81.                 Inc  Si                         ;Forward Strg2 Ptr
  82.                 Mov  Al,[Si]                    ;Get Strg2 Char
  83.                 Cmp  Al,Es:[Di]                 ;Compare To Strg1 Char
  84.                 Je   Compare4                   ;Loop If Equal
  85.                 Cmp  Al,122                     ;Above Lower Case Vals?
  86.                 Ja   Compare6                   ;Quit If So
  87.                 Cmp  Al,97                      ;Lower Case Char?
  88.                 Jnae Compare2                   ;Jump Ahead If Not
  89.                 Sub  Al,32                      ;Make Lower Case
  90.                 Jmp  Short Compare3             ;Go Test It
  91. Compare2:       Cmp  Al,90                      ;Above Upper Case Vals?
  92.                 Ja   Compare6                   ;Quit If So
  93.                 Cmp  Al,65                      ;Upper Case Char?
  94.                 Jnae Compare6                   ;Quit If Not
  95.                 Add  Al,32                      ;Make Lower Case
  96. Compare3:       Cmp  Al,Es:[Di]                 ;Compare To Strg1 Char
  97.                 Jne  Compare6                   ;Quit If Not Equal
  98. Compare4:       Loop Compare1                   ;Go Do Next Char
  99. Compare5:       Mov  Al,1                       ;Return True
  100.                 Jmp  Short Compare7             ;Jump Ahead
  101. Compare6:       Mov  Al,0                       ;Return False
  102. Compare7:       Pop  Ds                         ;Restore Ds And Quit
  103.                 Ret  8
  104. Compare Endp
  105.  
  106.  
  107. ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  108. ;Function Stringend(Strx: Stype; Numberchars: Integer): Stype;
  109. ;
  110. ;
  111. Data    Segment
  112.         Extrn  Errreturn:Byte
  113. Data    Ends
  114. ;
  115. ;
  116. Stringend Proc Far
  117.                 Push Bp                         ;Save Bp
  118.                 Mov  Bp,Sp                      ;Set Up Stack Frame
  119.                 Push Ds                         ;Save Ds
  120.                 Les  Di,Dword Ptr[Bp+12]        ;Es:Di Pts To Return Strx
  121.                 Lds  Si,Dword Ptr[Bp+8]         ;Ds:Si Pts To Source Strx
  122.                 Sub  Cx,Cx                      ;Clear Cx
  123.                 Mov  Es:[Di],Cl                 ;Return Null String If Error
  124.                 Mov  Cl,[Bp+6]                  ;Get Numberchars (255 Max)
  125.                 Sub  Bx,Bx                      ;Clear Bx
  126.                 Mov  Bl,[Si]                    ;Strx Length In Bx
  127.                 Mov  Dl,1                       ;1 = Null String
  128.                 Or   Bl,Bl                      ;Test For Null String
  129.                 Jz   Stringend3                 ;Quit Routine If Null
  130.                 Dec  Dl                         ;0 = No Error
  131.                 Cmp  Cx,Bx                      ;Numberchars < Length?
  132.                 Jbe  Stringend1                 ;Jump Ahead If So
  133.                 Mov  Cx,Bx                      ;Else Return Whole String
  134.                 Mov  Dl,2                       ;2 = Numberchars Greater Than Length
  135. Stringend1:     Mov  Es:[Di],Cl                 ;Return Strx Descriptor
  136.                 Sub  Bx,Cx                      ;Length Minus Numberchars
  137.                 Inc  Di                         ;Forward Return Strx Ptr To First Char
  138.                 Inc  Si                         ;Save For Source Strx
  139.                 Add  Si,Bx                      ;Add Starting Offset To Source
  140. Stringend2:     Cld                             ;Direction Forward
  141.                 Rep Movsb                       ;Move The Portion Of The String
  142. Stringend3:     Pop  Ds                         ;Restore Ds
  143.                 Mov  Errreturn,Dl               ;Set Errreturn
  144.                 Pop  Bp                         ;Restore Bp And Quit
  145.                 Ret  6
  146. Stringend Endp
  147.  
  148.  
  149.  
  150. ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  151. ;Procedure Deletechar(Var Strx: Stype; Ch: Char);
  152. ;
  153. ;
  154. Data    Segment
  155.         Extrn Errreturn:Byte
  156. Data    Ends
  157. ;
  158. ;
  159. ;
  160. Dele